"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.appendOptions = appendOptions;
exports.getConfig = getConfig;

function getConfig(target, configs, assets, onNodeCreate) {
  var {
    title,
    search,
    options
  } = configs;
  return {
    title,
    target,
    animation: false,
    validateNode: node => {
      onNodeCreate && onNodeCreate(node);
      return false;
    },
    getDragNode: node => {
      var {
        value,
        moduleType,
        moduleImage
      } = node.data;
      var image = assets[moduleImage] || assets["".concat(moduleType ? moduleType : value, "Module")] || moduleImage;
      return target.createNode({
        shape: 'lane-node',
        label: node.label,
        data: node.data,
        attrs: {
          body: {
            fill: '#ccc'
          },
          itemTag: {
            xlinkHref: image
          },
          backgorund: {
            xlinkHref: assets['innerSystem']
          }
        }
      });
    },
    search: (cell, keyword) => {
      if (keyword) {
        return cell.shape === 'moduleNode' && "".concat(cell.attr('text/text')).toLowerCase().includes("".concat(keyword).toLowerCase());
      }

      return true;
    },
    placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || '请输入组件名称',
    stencilGraphWidth: 200,
    collapsable: false,
    groups: options.map(_ref => {
      var {
        label,
        value,
        children
      } = _ref;
      return {
        title: label,
        name: value,
        collapsable: false,
        graphPadding: 0,
        graphHeight: (Array.isArray(children) ? children.length * 32 : 0) + 10,
        layoutOptions: {
          columns: 1,
          columnWidth: 190,
          rowHeight: 32,
          dx: 5,
          dy: 5
        }
      };
    })
  };
}

function appendOptions(graph, stencil, options, assets) {
  var moduleProps = {};
  var modules = {};
  options.forEach(group => {
    var {
      value: groupName,
      children
    } = group;
    if (!Array.isArray(children)) return;
    var items = children.map(item => {
      var {
        label,
        value,
        icon,
        moduleType,
        moduleProp
      } = item;
      moduleProps[moduleType || value] = moduleProp;
      modules[moduleType || value] = item;
      delete item.moduleProp;
      var image = assets["".concat(icon, "Icon")] || icon;
      item.moduleType = moduleType || value;
      var node = graph.createNode({
        shape: 'moduleNode',
        label,
        data: item
      });
      node.attr('icon/xlinkHref', image);
      return node;
    });
    stencil.load(items, groupName);
  });
  window._moduleProps = moduleProps;
  window._modules = modules;
}